[Feat] CLI Login#928
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|
screenshots if possible @HeshamHM28 |
| return self._get_error_html("unauthorized", theme) | ||
|
|
||
| @staticmethod | ||
| def _get_loading_html(theme: str = "light") -> str: |
There was a problem hiding this comment.
why do we have html in the cli?
There was a problem hiding this comment.
That is for the local server used on local machines.
| # Setup PKCE | ||
| port = oauth.get_free_port() | ||
| redirect_uri = f"http://localhost:{port}/callback" | ||
| code_verifier, code_challenge = oauth.generate_pkce_pair() |
There was a problem hiding this comment.
is generating this in the cli side where the user can modify this generation logic a security vulnerability? what is user has full control of the generation string, would that degrade the security somehow?
There was a problem hiding this comment.
It is safe because we ensure the user is authenticated in cf-webapp before exchanging the code. Even if the user overrides this value, they will still receive their own API key.
| def start_local_server(self, port: int) -> http.server.HTTPServer: | ||
| """Start local HTTP server for OAuth callback.""" | ||
| handler_class = self.create_callback_handler() | ||
| httpd = http.server.HTTPServer(("localhost", port), handler_class) |
There was a problem hiding this comment.
wait, we are doing local server way of authentication? this won't work in remote machines.
why are we not doing polling?
There was a problem hiding this comment.
I implemented remote-machine logic in the last commit.
Co-authored-by: codeflash-ai[bot] <148906541+codeflash-ai[bot]@users.noreply.github.com>
|
This PR is now faster! 🚀 HeshamHM28 accepted my code suggestion above. |
⚡️ Codeflash found optimizations for this PR📄 11% (0.11x) speedup for
|
aseembits93
left a comment
There was a problem hiding this comment.
waiting for #931 to be merged @KRRT7 @HeshamHM28
|
why do we want TUI to be merged for this? we should merge this first |
Because this change will require additional updates to TUI, so @KRRT7 suggested merging it after TUI. |
|
merge this first for the CLI init. we still need to experiment more with TUI to make a decision to see if it is going to be better than the cli init for the users. |
|
let's merge it in now, the TUI flow currently requires a bit more testing before merging it in |
Fixes cf-841
Screen.Recording.2025-11-18.at.12.05.33.AM.mov
PR Type
Enhancement
Description
Add OAuth PKCE login flow
CLI prompt supports login or API key
Save OAuth token as API key
Improve auth success/error UX
Diagram Walkthrough
File Walkthrough
cmd_init.py
CLI prompt adds OAuth login pathcodeflash/cli_cmds/cmd_init.py
perform_oauth_signinand save tokenoauth_handler.py
New OAuth handler with PKCE and local HTTPcodeflash/code_utils/oauth_handler.py
perform_oauth_signinhelper for CLI